<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>

    <style>
        body{background:url(image/login.jpg) #f1f2f4 center top no-repeat; background-size: 100% auto;}
    </style>
    <header class="login-head" style="padding-top:0.4rem;">
        <div class="login-head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>登录</h3>
    </header>
    <div class="login-logo">
        <img src="image/logo.png">
    </div>

    <ul class="login">
        <li>
            <label>手机号码</label>
            <input type="text" placeholder="请输入手机号" id="email">
        </li>
        <li>
            <label>登录密码</label>
            <input type="password" placeholder="请输入登录密码" id="password">
        </li>
    </ul>

    <div class="btn-1 mt100 mb30" tapmode onclick="login();">登录</div>

    <div class="login-d">
        <span tapmode onclick="register_1()">注册</span>
        <span tapmode onclick="forgetPwd()">忘记密码</span>
    </div>

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">

    apiready = function(){


    }

    // 登录
    function login() {

        $('#password').blur();

        var email = $api.byId('email').value;
        var password = $api.byId('password').value;
        var registrationId = $api.getStorage('registrationId');
        // if (!email) {
        //     api.toast({
        //         msg: '请输入手机号!',
        //         duration: 2000,
        //         location: 'bottom'
        //     });
        //     return false;
        // }
        // if (!password) {
        //     api.toast({
        //         msg: '请输入密码!',
        //         duration: 2000,
        //         location: 'bottom'
        //     });
        //     return false;
        // }
        // alert(registrationId);
        api.ajax({
            url: webAddress + '/api/auth/login',
            method: 'post',
            data: {
                values: {
                    email: email,
                    password: password,
                    push_id: registrationId,
                },
            }
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                $api.setStorage('token', ret.token);
                // 给小游戏存储唯一标示
                $api.setStorage('game_userid', ret.id);

                api.toast({
                    msg: '登陆成功!',
                    duration: 2000,
                    location: 'bottom',
                    global: true,
                });

                var backUrl = api.pageParam.backUrl;
                if (backUrl == 'userindex') {
                    var setSele = 'gotoUserIndex();';
                    api.execScript({
                        name: 'root',
                        script: setSele,
                    });
                }else{    
                    api.sendEvent({
                      name: 'reload'
                  });
                }
                api.closeWin();
            } else {
                // alert( JSON.stringify( err ) );
                if(err.statusCode == 400){
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });
    }

    function register_1() {
        api.openWin({
            name: 'register_1',
            url: './register_1.html',
        });
    }

    function forgetPwd() {
        api.openWin({
            name: 'forget_pwd',
            url: './forget_pwd.html',
        });
    }

    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>
